/*
 * @Author: TC
 * @Date: 2025-04-23 10:12:13
 * @Last Modified by: TC
 * @Last Modified time: 2025-05-05 01:40:14
 */

import { _decorator } from "cc";
import { IPoolItemData } from "../../Common/BaseInterface";
import { PoolUnit } from "../Pool/PoolUnit";
import { BaseComponent } from "./BaseComponent";

const { ccclass, property } = _decorator;

/**
 * 对象池节点基类
 */
@ccclass("BasePoolItem")
export class BasePoolItem extends BaseComponent {
    //所属对象池
    private _pool: PoolUnit;
    //节点数据
    protected _data: IPoolItemData;

    /**
     * 每次动对象池中取出时设置数据
     * 在onGet之后调用
     * @param data
     */
    public setData(data: IPoolItemData): void {
        this._data = data;
    }

    /**
     * 获取节点数据
     * @returns
     */
    public getData(): IPoolItemData {
        return this._data;
    }

    setPool(pool: PoolUnit): void {
        this._pool = pool;
    }
    getPool(): PoolUnit {
        return this._pool;
    }

    /**
     * 从对象池取出时的回调
     */
    onGet(): void {}

    /**
     * 被放入对象池时的回调
     */
    onPut(): void {}

    /**
     * 将节点放入对象池
     */
    putToPool(): void {
        this._pool.put(this.node);
    }
    onDestroy() {
        super.onDestroy();
    }
}
